/* Copyright (c) 2010-2020 Vadim Surov.
 */
package com.srv.client.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;
import com.srv.client.Oneortwo;
import com.srv.client.Registry;
import com.srv.client.event.StudioEvent;
import com.srv.client.event.HomeEvent;
import com.srv.client.event.RunEvent;
import com.srv.client.event.SessionEvent;
import com.srv.shared.LoginInfo;

public class BasePresenter implements Presenter {  

	private final HandlerManager eventBus;

	private final Display display;

	public BasePresenter(Display view) {
		this.display = view;
		eventBus = Registry.get(Oneortwo.EVENTBUS);
	}

	public void bind() {
		display.getHomeButton().addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new HomeEvent());
			}
		});
		display.getDesignButton().addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new StudioEvent());
			}
		});
		display.getSessionButton().addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new SessionEvent());
			}
		});
		display.getRunButton().addClickHandler(new ClickHandler() {   
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new RunEvent());
			}
		});
	}

	public void go(final HasWidgets container) {
		bind();
		container.clear();
		container.add(display.asWidget());
	}

	public void onLogin(LoginInfo loginInfo) {
		display.onLogin(loginInfo);
	}

}
